<template>
  <div class="tpl48-head">
    <section class="modulePadding">
      <div class="swiper_bg65">
        <div class="search_goods65">
          <a @click="JumpName('item-class-list')" class="ico_menu"><i></i><span>分类</span></a>
          <form class="search_form">
            <div class="formitem">
              <button type="submit" class="j-search-button btn_sele" @click="searchList"></button>
              <input class="btn_sele_input" type="text" name="title" :focus="focus" placeholder="请输入商品名称" @blur="blurInput" v-model="keyword" @click="focusInput" @confirm="searchList"/>
            </div>
          </form>
          <a @click="JumpName('member')" class="ico_user"><i></i><span>会员</span></a>
        </div>
        <div class="members_flash_box65">
          <section class="members_flash members_flash65 j-swipe" id="Swiper0">
            <ul class="clearfix swiper-ul" v-if="tplItemData.content">
              <!-- TODO 小程序端用swiper -->
              <wx-swiper :style="{height:imgadvWxH}" :circular="true" :autoplay="autoplay">
                <wx-swiper-item v-for="(item,index) in tplItemData.content.dataset" :key="index">
                  <a href="javascript:;" @click="openLink(item.link)">
                    <img class="img" :src="item.pic" @load="onImageLoad($event)"/>
                  </a>
                </wx-swiper-item>
              </wx-swiper>
              
            </ul>
          </section>
        </div>
      
        <section class="list_menu">
          <ul v-if="tplItemData.content">
            <li v-for="(item,index) in tplItemData.content.dataset_btn" :key="index">
              <a @click="openLink(item.link)">
                <img :src="item.pic" />
                <p>{{ item.showtitle }}</p>
              </a>
            </li>
          </ul>
        </section>
      </div>
  
    </section>
    
  </div>
</template>

<script>
  import Vue from 'vue'
  import { openPage } from '@/utils/utils'

  export default Vue.extend({
    props: {
      tplItemData: {
        type: Object
      }
    },
    data() {
      return {
        autoplay: true,
        keyword: '',
        imgadvWxH: 0,
        focus: false
      }
    },
    methods: {
      openLink(link) {
        if (link) {
          openPage(link)
        }
      },
      // 小程序swiper获取图片高度
      onImageLoad(event){
        const imgHeight = event.detail.height
        if(imgHeight > parseFloat(this.imgadvWxH)){
          this.imgadvWxH = imgHeight+'px'
        }
      },
      /**
       * 搜索商品
       */
      searchList() {
        this.$JumpName(this, 'item-list', { title: this.keyword })
      },
      focusInput() {
        this.focus = true
      },
      blurInput() {
        this.focus = false
      },
      /**
       * 链接跳转
       */
      JumpName(url, data) {
        this.$JumpName(this, url, data)
      }
    }
  })
</script>

<style lang="scss">
  @import "src/styles/mixin";
  .tpl48-head{
    // 首页模板65
    .swiper_bg65{
      position:relative;
      .img{
        width: 100%;
      }
    }
    .swiper-ul {
      img {
        width: 100%;
      }
    }
    .search_goods65{
      position:absolute;
      top:0;
      left:0;
      z-index:10;
      width:100%;
      text-align: center;
      padding: 20px 10px;
      -moz-box-sizing: border-box;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      &>a{
        display: inline-block;
        *display:inline;
        *zoom:1;
        width:74px;
        height:74px;
        // padding:0 5px;
        border-radius:50%;
        text-align: center;
        color: #fff;
        font-size:24px;
        background:rgba(0,0,0,.5);
        i{
          display: block;
          height: 28px;
          width:26px;
          margin:10px auto 0px;
          background-repeat:no-repeat;
          background-position:center;
          background-size:contain;
        }
        span{
          font-size: 20px;
          line-height:1;
        }
        &.ico_menu{
          margin-right: 2%;
          i{
            background-image:url(https://img.wifenxiao.com/h5-wfx/images/diy/tpl48/65menu.png);
          }
        }
        &.ico_user{
          margin-left: 2%;
          i{
            background-image:url(https://img.wifenxiao.com/h5-wfx/images/diy/tpl48/65user.png);
          }
        }
      }
      .search_form{
        display: inline-block;
        background: #fff;
        vertical-align: top;
        border:2px solid #fff;
        border-radius: 30px;
        padding: 6px 0;
        width: 68%;
        .btn_sele{
          width: 40px;
          height: 40px;
          border: none;
          background-image: url(https://img.wifenxiao.com/h5-wfx/images/diy/tpl48/65select.png);
          background-repeat: no-repeat;
          background-position: center center;
          background-size: 36px 36px;
          float: left;
          margin: 4px 0 0 16px;
          background-color: transparent;
        }
        input{
          width: 80%;
          height: 28px;
          min-height: initial;
          line-height: 28px;
          border: none;
          font-size:28px;
          background: transparent;
          margin: 10px 0;
          color:#666;
          &::-webkit-input-placeholder{    /* WebKit, Blink, Edge */
            color:#999;
          }
          &::-moz-placeholder{    /* Mozilla Firefox 19+ */
            color:#999;
          }
          &:-moz-placeholder{     /* Mozilla Firefox 4 to 18 */
            color:#999;
          }
          &:-ms-input-placeholder{     /* Internet Explorer 10-11 */
            color:#999;
          }
        }
      }
    }
  
    .members_flash_time65{
      span{
        width:14px;
        height:4px;
        border-radius:4px;
        margin: 0 2px;
        background:#fff;
        &.cur{
          width:28px;
          background:rgba(249,69,78,.58);
        }
      }
      margin-bottom:6%;
    }
  
    .list_menu{
      position: relative;
      margin-top: -5%;
      ul{
        display: flex;
        display:-webkit-box;
        display:-webkit-flex;
        flex-wrap: wrap;
        -webkit-flex-wrap:wrap;
        -moz-flex-wrap:wrap;
        flex-direction: row;
        -webkit-flex-direction: row;
        -moz-flex-direction: row;
        justify-content: space-between;
        -webkit-justify-content: space-between;
        -moz-justify-content: space-between;
        // margin: 0 10px;
        margin-left: 3.125%;
        margin-right: 3.125%;
        padding: 4% 2% 1%;
        border-radius: 8px;
        text-align: center;
        background: #fff;
        li{
          width: 17%;
          text-align: center;
          margin: 0 1% 3.5%;
          img{
            display:block;
            width: 96px;
            height: 96px;
            margin:0 auto;
          }
          p{
            line-height: 30px;
            padding-top: 10px;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
            color: #666;
          }
        }
      }
    }
    .formitems{
      .adv_si{
        padding-left: 240px;
        color: #666;
        font-size: 22px;
      }
    }
  
  }
  .btn_sele_input {
    margin: 0;
    height: 44px;
    line-height: 44px;
  }
</style>
